
<template>
  <!-- 修改图纸界面可修改图纸总面积、软体区总面积、套房区总面积、是否含成融定、成融定面积、新业务总面积字段 -->
  <c-dialog ref="dialog" :open-fun="openFun" title="修改图纸" @open="openHandle" @closed="closedHandle">
    <c-list ref="form" :model="formData" :rules="formRules" label-width="100px">
      <c-list :column="2">
        <c-list-item label="图纸总面积" prop="picTotalArea">
          <el-input v-model.number="formData.picTotalArea" placeholder="图纸总面积" clearable />
        </c-list-item>
        <c-list-item label="软体区总面积" prop="softwareSumArea">
          <el-input v-model.number="formData.softwareSumArea" placeholder="软体区总面积" clearable />
        </c-list-item>
      </c-list>
      <c-list :column="2">
        <c-list-item label="套房区总面积" prop="suiteSumArea">
          <el-input v-model.number="formData.suiteSumArea" placeholder="套房区总面积" clearable />
        </c-list-item>
        <c-list-item label="是否含成融定" prop="haveEAndC">
          <el-radio-group v-model="formData.haveEAndC">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </c-list-item>
      </c-list>
      <c-list :column="2">
        <c-list-item label="成融定面积" prop="eandCArea">
          <el-input v-model.number="formData.eandCArea" placeholder="成融定面积" clearable />
        </c-list-item>
        <c-list-item label="新业务总面积" prop="newBusinessAreaSummary">
          <el-input v-model.number="formData.newBusinessAreaSummary" placeholder="新业务总面积" clearable />
        </c-list-item>
      </c-list>
      <c-list :column="1">
        <c-list-item>
          <div class="btn-container">
            <c-button @click="cancelHandle">取消</c-button>
            <c-button key="confirm" type="primary" @click="confirmHandle">确认</c-button>
          </div>
        </c-list-item>
      </c-list>
    </c-list></c-dialog>
</template>
<script>
import { saveDrawing } from '@/api/shopDrawing'
export default {
  name: 'DrawingEdit',
  components: {
  },
  props: {
    selData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      formData: {
        id: '',
        picTotalArea: undefined,
        softwareSumArea: undefined,
        suiteSumArea: undefined,
        haveEAndC: undefined,
        eandCArea: undefined,
        newBusinessAreaSummary: undefined,
        picTaskCode: '',
        designTaskCode: '',
        picTaskName: '',
        picType: '',
        designRange: ''
      },
      formRules: {
        // designLog: [{ required: true, message: '请填写图纸设计日志', trigger: 'change' }]
      }
    }
  },
  computed: {
    detail() {
      return this.selData.length === 0 ? {} : this.selData[0]
    }
  },
  methods: {
    openFun() {
      if (!this.singleJudge(this.selData, '修改', true)) {
        return false
      }
      // const d = this.selData[0]
      // if (d.state !== 'ABNORMAL') {
      //   this.$message.warning('异常暂停的图纸，才能编辑图纸设计日志')
      //   return false
      // }
      return true
    },
    openHandle() {
      const { id, designTaskCode, picTaskCode, picTaskName, picType, designRange, picTotalArea = undefined, softwareSumArea = undefined, suiteSumArea = undefined,
        haveEAndC = undefined, eandCArea = undefined, newBusinessAreaSummary = undefined } = this.detail
      this.formData = { id, designTaskCode, picTaskCode, picTaskName, picType, designRange, picTotalArea, softwareSumArea, suiteSumArea,
        haveEAndC, eandCArea, newBusinessAreaSummary }
    },
    closedHandle() {
      this.formData = {
        id: '',
        picTotalArea: undefined,
        softwareSumArea: undefined,
        suiteSumArea: undefined,
        haveEAndC: undefined,
        eandCArea: undefined,
        designTaskCode: '',
        newBusinessAreaSummary: undefined,
        picTaskCode: '',
        picTaskName: '',
        picType: '',
        designRange: ''
      }
    },
    confirmHandle() {
      return this.$refs.form.validate().then(() => {
        return saveDrawing(this.formData).then(res => {
          this.$message.success('操作成功！')
          this.$refs.dialog.visible = false
          this.$emit('on-success')
        })
      })
    },
    cancelHandle() {
      this.$refs.dialog.visible = false
      this.closedHandle()
    }
  }
}
</script>
